#include "Box.hpp"
#include "PhysicEngine.hpp"
#include "Map.hpp"

Box::Box(Map& map, const int x, const int y, const unsigned int index):
sf::Sprite(),
m_body(NULL),
m_map(map),
m_index(index)
{
	this ->SetCenter(20,20);
	// create body
    b2BodyDef bd;
    bd.position.Set(float(x)/40.f,600.f/40.f - float(y)/40.f -0.5f);
	m_body = PhysicEngine::instance().world()->CreateBody(&bd);
	this->SetPosition(bd.position.x * 40.f, 600.f - 40.f *bd.position.y);
	b2PolygonShape shape;
	shape.SetAsBox(0.5f,0.5f);
	m_body->CreateFixture(&shape, 0.0f);
}

		
Box::Box(const Box& b):
sf::Sprite(b),
m_body(b.m_body),
m_map(b.m_map),
m_index(b.m_index)
{

}

Box& Box::operator=(const Box& b)
{
	sf::Sprite::operator=(b);
	m_body = b.m_body;
	m_map = b.m_map;
	m_index = b.m_index;
	
	return *this;
}

Box::~Box()
{
	PhysicEngine::instance().world()->DestroyBody(m_body);
}
